package com.example.anew.journey.mynewjourney.customview;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

import static android.view.View.MeasureSpec.getSize;

/**
 * 杭州惟君医疗科技有限公司16
 * Created by 20433 on 2018/3/23
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class MyRelativeLayoutImageView extends ImageView {
    public MyRelativeLayoutImageView(Context context) {
        super(context);
    }

    public MyRelativeLayoutImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRelativeLayoutImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
       float width =   MeasureSpec.getSize(widthMeasureSpec);
        float height =  MeasureSpec.getSize(heightMeasureSpec);
        Drawable imgDrawable = getDrawable();
        float date = 0f;
        if (imgDrawable != null) {
            //获得ImageView中Image的真实宽高，
            int dw = imgDrawable.getBounds().width();
            int dh = imgDrawable.getBounds().height();
            date =(float) dh/dw;
        }

        setMeasuredDimension((int)width,(int)(width*date));
    }


}
